const express = require("express");
const bodyParser = require("body-parser");
const commandRoutes = require("./v1/routes/command");
const { initDatabase } = require("./config/db");
const wechatRoutes = require("./v1/routes/wechat");
const uploadCosRoutes = require("./v1/routes/uploadCos");
const adminRoutes = require("./v1/routes/admin"); // 添加后台管理路由
require("dotenv").config();

const app = express();

app.use(
  bodyParser.json({
    verify: (req, res, buf, encoding) => {
      try {
        JSON.parse(buf.toString(encoding));
      } catch (e) {
        res.status(400).send({ error: "Invalid JSON format" });
      }
    },
  })
);
// 暂时不存数据库
// initDatabase()
app.use("/api/v1", commandRoutes);
app.use("/api/v1", wechatRoutes);
app.use("/api/v1", uploadCosRoutes);
app.use("/api/v1/admin", adminRoutes); // 添加后台管理路由

module.exports = app;



